;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 3.7.1 #0 (MSVC)
;--------------------------------------------------------
; NY8A port
;--------------------------------------------------------
	.file	"components\touch_key\touch_key.c"
	list	p=NY8B062E,c=on
	#include "ny8b062e.inc"
	.debuginfo language C89
;--------------------------------------------------------
; external declarations
;--------------------------------------------------------
	extern	_sinf
	extern	_cosf
	extern	_tanf
	extern	_cotf
	extern	_asinf
	extern	_acosf
	extern	_atanf
	extern	_atan2f
	extern	_sinhf
	extern	_coshf
	extern	_tanhf
	extern	_expf
	extern	_logf
	extern	_log10f
	extern	_powf
	extern	_sqrtf
	extern	_fabsf
	extern	_frexpf
	extern	_ldexpf
	extern	_ceilf
	extern	_floorf
	extern	_modff
	extern	_isnan
	extern	_isinf
	extern	_multi_16b
	extern	_read_14bit_rom
	extern	_Adc_Start
	extern	_Adc_SetVref
	extern	_Adc_GetOnce
	extern	_Mcu_Delayus
	extern	_Mcu_Delayms
	extern	_Btn_Loop
	extern	_Btn_Init
	extern	_SoftCT_EvIOInt
	extern	_SoftCT_EvTimeout
	extern	_SoftCT_GetEvent
	extern	_SoftCT_Run
	extern	_SoftCT_Stop
	extern	_CapSS_Init
	extern	_CapSS_GetValue
	extern	_PORTAbits
	extern	_PORTBbits
	extern	_PCONbits
	extern	_BWUCONbits
	extern	_ABPLCONbits
	extern	_BPHCONbits
	extern	_INTEbits
	extern	_INTFbits
	extern	_ADMDbits
	extern	_ADRbits
	extern	_ADVREFHbits
	extern	_ADCRbits
	extern	_AWUCONbits
	extern	_PACONbits
	extern	_ADJMDbits
	extern	_INTEDGbits
	extern	_ANAENbits
	extern	_RFCbits
	extern	_INTE2bits
	extern	__Adc_mDiscard
	extern	__Polsys_mTicked
	extern	__Btn_mIsDown
	extern	_SoftCT_mCaptureValue
	extern	_INDF
	extern	_TMR0
	extern	_PCL
	extern	_STATUS
	extern	_FSR
	extern	_PORTA
	extern	_PORTB
	extern	_PCON
	extern	_BWUCON
	extern	_PCHBUF
	extern	_ABPLCON
	extern	_BPHCON
	extern	_INTE
	extern	_INTF
	extern	_ADMD
	extern	_ADR
	extern	_ADD
	extern	_ADVREFH
	extern	_ADCR
	extern	_AWUCON
	extern	_PACON
	extern	_ADJMD
	extern	_INTEDG
	extern	_TMRH
	extern	_ANAEN
	extern	_RFC
	extern	_TM3RH
	extern	_INTE2
	extern	_TMR1
	extern	_T1CR1
	extern	_T1CR2
	extern	_PWM1DUTY
	extern	_PS1CV
	extern	_BZ1CR
	extern	_IRCR
	extern	_TBHP
	extern	_TBHD
	extern	_TMR2
	extern	_T2CR1
	extern	_T2CR2
	extern	_PWM2DUTY
	extern	_PS2CV
	extern	_BZ2CR
	extern	_OSCCR
	extern	_TMR3
	extern	_T3CR1
	extern	_T3CR2
	extern	_PWM3DUTY
	extern	_PS3CV
	extern	_BZ3CR
	extern	_P4CR1
	extern	_PWM4DUTY
	extern	_IOSTA
	extern	_IOSTB
	extern	_APHCON
	extern	_PS0CV
	extern	_BODCON
	extern	_CMPCR
	extern	_PCON1
	extern	_T0MD

	extern PSAVE
	extern SSAVE
	extern WSAVE
	extern STK04
	extern STK03
	extern STK02
	extern STK01
	extern STK00
;--------------------------------------------------------
; global declarations
;--------------------------------------------------------
	extern	_TouchKey_Scan
	extern	_TouchKey_Init
	extern	_TouchKey_mKeyStatus

;--------------------------------------------------------
; global definitions
;--------------------------------------------------------
.segment "uninit"
_TouchKey_mKeyStatus:
	.res	1
	.debuginfo gvariable name=_TouchKey_mKeyStatus,1byte,array=0,entsize=1,ext=1,enc=unsigned

;--------------------------------------------------------
; absolute symbol definitions
;--------------------------------------------------------
;--------------------------------------------------------
; compiler-defined variables
;--------------------------------------------------------
.segment "uninit"
r0x100D:
	.res	1
.segment "uninit"
r0x1008:
	.res	1
.segment "uninit"
r0x1007:
	.res	1
.segment "uninit"
r0x1009:
	.res	1
.segment "uninit"
r0x100A:
	.res	1
.segment "uninit"
r0x100C:
	.res	1
.segment "uninit"
_mRefValue:
	.res	2
	.debuginfo gvariable name=_mRefValue,2byte,array=0,entsize=1,ext=0,enc=unsigned
.segment "uninit"
_mKeyDownCont:
	.res	2
	.debuginfo gvariable name=_mKeyDownCont,2byte,array=0,entsize=1,ext=0,enc=unsigned
.segment "uninit"
_mKeyUpCont:
	.res	2
	.debuginfo gvariable name=_mKeyUpCont,2byte,array=0,entsize=1,ext=0,enc=unsigned
;--------------------------------------------------------
; initialized data
;--------------------------------------------------------
;--------------------------------------------------------
; overlayable items in internal ram 
;--------------------------------------------------------
;	udata_ovr
;--------------------------------------------------------
; code
;--------------------------------------------------------
;***
;  pBlock Stats: dbName = C
;***
;has an exit
;functions called:
;   _CapSS_GetValue
;   _CapSS_GetValue
;7 compiler assigned registers:
;   r0x1007
;   STK00
;   r0x1008
;   r0x1009
;   r0x100A
;   r0x100B
;   r0x100C
;; Starting pCode block
.segment "code"; module=touch_key, function=_TouchKey_Scan
	.debuginfo subprogram _TouchKey_Scan
;local variable name mapping:
	.debuginfo variable _cap_value[0]=r0x1008,enc=unsigned
	.debuginfo variable _cap_value[1]=r0x1007,enc=unsigned
	.debuginfo variable _diff_value[0]=r0x1009,enc=signed
	.debuginfo variable _diff_value[1]=r0x100A,enc=signed
_TouchKey_Scan:
; 2 exit points
	.line	242, "components\touch_key\touch_key.c"; 	cap_value = _TouchKey_CapSSGetValue(0);
	MCALL	_CapSS_GetValue
	BANKSEL	r0x100A
	MOVAR	r0x100A
	BANKSEL	r0x1007
	MOVAR	r0x1007
	MOVR	STK00,W
	BANKSEL	r0x1008
	MOVAR	r0x1008
	.line	243, "components\touch_key\touch_key.c"; 	diff_value = (s16)cap_value - (s16)mRefValue;
	BANKSEL	r0x1009
	MOVAR	r0x1009
;;99	MOVR	r0x1007,W
	BANKSEL	_mRefValue
	MOVR	_mRefValue,W
;;1	MOVAR	r0x100B
	BANKSEL	r0x1009
	SUBAR	r0x1009,F
;;100	MOVR	r0x100C,W
	BANKSEL	_mRefValue
	MOVR	(_mRefValue + 1),W
	BANKSEL	r0x100C
	MOVAR	r0x100C
	BTRSS	STATUS,0
	INCR	r0x100C,W
	BTRSC	STATUS,2
	MGOTO	_00001_DS_
	BANKSEL	r0x100A
	SUBAR	r0x100A,F
_00001_DS_:
	.line	251, "components\touch_key\touch_key.c"; 	if (TouchKey_mKeyStatus) // 现在是按下状态
	BANKSEL	_TouchKey_mKeyStatus
	MOVR	_TouchKey_mKeyStatus,W
	BTRSC	STATUS,2
	MGOTO	_00131_DS_
;;swapping arguments (AOP_TYPEs 1/2)
;;signed compare: left >= lit (0x6=6), size=2, mask=ffff
	.line	253, "components\touch_key\touch_key.c"; 	if (diff_value <= INVALID_VALUE) //可能松手了
	BANKSEL	r0x100A
	MOVR	r0x100A,W
	ADDIA	0x80
	ADDIA	0x80
	BTRSS	STATUS,2
	MGOTO	_00162_DS_
	MOVIA	0x06
	BANKSEL	r0x1009
	SUBAR	r0x1009,W
_00162_DS_:
	BTRSC	STATUS,0
	MGOTO	_00114_DS_
	.line	260, "components\touch_key\touch_key.c"; 	TouchKey_mKeyStatus = false; //标记松手了
	BANKSEL	_TouchKey_mKeyStatus
	CLRR	_TouchKey_mKeyStatus
	.line	261, "components\touch_key\touch_key.c"; 	mKeyDownCont = 0;
	BANKSEL	_mKeyDownCont
	CLRR	_mKeyDownCont
	CLRR	(_mKeyDownCont + 1)
	.line	261, "components\touch_key\touch_key.c"; 	#ifdef _TOUCH_HOLD_ABNORMAL_PROTECTION
	MGOTO	_00133_DS_
_00114_DS_:
	.line	275, "components\touch_key\touch_key.c"; 	mKeyUpCont = 0;
	BANKSEL	_mKeyUpCont
	CLRR	_mKeyUpCont
	CLRR	(_mKeyUpCont + 1)
	.line	276, "components\touch_key\touch_key.c"; 	mKeyDownCont++;
	BANKSEL	_mKeyDownCont
	INCR	_mKeyDownCont,F
	BTRSC	STATUS,2
	INCR	(_mKeyDownCont + 1),F
	.line	295, "components\touch_key\touch_key.c"; 	if (mKeyDownCont == (_TOUCH_KEY_RESET_TIMEOUT / _TOUCH_KEY_SCAN_INTERVAL)) //超时重置基准值
	MOVR	_mKeyDownCont,W
	XORIA	0xdc
	BTRSS	STATUS,2
	MGOTO	_00133_DS_
	MOVR	(_mKeyDownCont + 1),W
	XORIA	0x05
	BTRSS	STATUS,2
	MGOTO	_00133_DS_
	.line	297, "components\touch_key\touch_key.c"; 	mRefValue = cap_value;
	BANKSEL	r0x1008
	MOVR	r0x1008,W
	BANKSEL	_mRefValue
	MOVAR	_mRefValue
	BANKSEL	r0x1007
	MOVR	r0x1007,W
	BANKSEL	_mRefValue
	MOVAR	(_mRefValue + 1)
	.line	297, "components\touch_key\touch_key.c"; 	}
	MGOTO	_00133_DS_
;;signed compare: left < lit (0x7=7), size=2, mask=ffff
_00131_DS_:
	.line	303, "components\touch_key\touch_key.c"; 	if (diff_value >= VALID_VALUE) // 可能按下了
	BANKSEL	r0x100A
	MOVR	r0x100A,W
	ADDIA	0x80
	ADDIA	0x80
	BTRSS	STATUS,2
	MGOTO	_00163_DS_
	MOVIA	0x07
	BANKSEL	r0x1009
	SUBAR	r0x1009,W
_00163_DS_:
	BTRSS	STATUS,0
	MGOTO	_00128_DS_
	.line	306, "components\touch_key\touch_key.c"; 	mKeyDownCont++;
	BANKSEL	_mKeyDownCont
	INCR	_mKeyDownCont,F
	BTRSC	STATUS,2
	INCR	(_mKeyDownCont + 1),F
;;unsigned compare: left < lit (0x2=2), size=2
	.line	307, "components\touch_key\touch_key.c"; 	if (mKeyDownCont >= _TOUCH_KEY_DOWN_VALID_CNT) // 连续2次检测到按下信号
	MOVIA	0x00
	SUBAR	(_mKeyDownCont + 1),W
	BTRSS	STATUS,2
	MGOTO	_00164_DS_
	MOVIA	0x02
	SUBAR	_mKeyDownCont,W
_00164_DS_:
	BTRSS	STATUS,0
	MGOTO	_00133_DS_
	.line	310, "components\touch_key\touch_key.c"; 	TouchKey_mKeyStatus = true; // 标记按下了
	MOVIA	0x01
	BANKSEL	_TouchKey_mKeyStatus
	MOVAR	_TouchKey_mKeyStatus
	.line	311, "components\touch_key\touch_key.c"; 	mKeyUpCont = 0;
	BANKSEL	_mKeyUpCont
	CLRR	_mKeyUpCont
	CLRR	(_mKeyUpCont + 1)
	.line	311, "components\touch_key\touch_key.c"; 	}
	MGOTO	_00133_DS_
_00128_DS_:
	.line	316, "components\touch_key\touch_key.c"; 	mKeyDownCont = 0;
	BANKSEL	_mKeyDownCont
	CLRR	_mKeyDownCont
	CLRR	(_mKeyDownCont + 1)
;;unsigned compare: left < lit (0xFFFF=65535), size=2
	.line	317, "components\touch_key\touch_key.c"; 	if (mKeyUpCont < 0xFFFF)
	MOVIA	0xff
	BANKSEL	_mKeyUpCont
	SUBAR	(_mKeyUpCont + 1),W
	BTRSS	STATUS,2
	MGOTO	_00165_DS_
	MOVIA	0xff
	SUBAR	_mKeyUpCont,W
_00165_DS_:
	BTRSC	STATUS,0
	MGOTO	_00119_DS_
	.line	318, "components\touch_key\touch_key.c"; 	mKeyUpCont++;
	BANKSEL	_mKeyUpCont
	INCR	_mKeyUpCont,F
	BTRSC	STATUS,2
	INCR	(_mKeyUpCont + 1),F
;;unsigned compare: left < lit (0xC8=200), size=2
_00119_DS_:
	.line	411, "components\touch_key\touch_key.c"; 	if (mKeyUpCont >= (_TOUCH_KEY_RESET_REF_INTERVAL / _TOUCH_KEY_SCAN_INTERVAL)) //松手的时间达到重置基准值
	MOVIA	0x00
	BANKSEL	_mKeyUpCont
	SUBAR	(_mKeyUpCont + 1),W
	BTRSS	STATUS,2
	MGOTO	_00166_DS_
	MOVIA	0xc8
	SUBAR	_mKeyUpCont,W
_00166_DS_:
	BTRSS	STATUS,0
	MGOTO	_00133_DS_
;;signed compare: left < lit (0xFFFFFFFD=-3), size=2, mask=ffff
	.line	413, "components\touch_key\touch_key.c"; 	if (diff_value >= _TOUCH_KEY_SAFE_RESET_DIFF) // 当前值在 基准值-1 以上
	BANKSEL	r0x100A
	MOVR	r0x100A,W
	ADDIA	0x80
	ADDIA	0x81
	BTRSS	STATUS,2
	MGOTO	_00167_DS_
	MOVIA	0xfd
	BANKSEL	r0x1009
	SUBAR	r0x1009,W
_00167_DS_:
	BTRSS	STATUS,0
	MGOTO	_00123_DS_
	.line	415, "components\touch_key\touch_key.c"; 	mRefValue = cap_value; // 直接作为新的基准值
	BANKSEL	r0x1008
	MOVR	r0x1008,W
	BANKSEL	_mRefValue
	MOVAR	_mRefValue
	BANKSEL	r0x1007
	MOVR	r0x1007,W
	BANKSEL	_mRefValue
	MOVAR	(_mRefValue + 1)
	.line	416, "components\touch_key\touch_key.c"; 	mKeyUpCont = 0;
	BANKSEL	_mKeyUpCont
	CLRR	_mKeyUpCont
	CLRR	(_mKeyUpCont + 1)
	MGOTO	_00133_DS_
;;unsigned compare: left < lit (0x5DC=1500), size=2
_00123_DS_:
	.line	420, "components\touch_key\touch_key.c"; 	if (mKeyUpCont >= (_TOUCH_KEY_RESET_TIMEOUT / _TOUCH_KEY_SCAN_INTERVAL)) //达到超时时间（无条件重置时间）
	MOVIA	0x05
	BANKSEL	_mKeyUpCont
	SUBAR	(_mKeyUpCont + 1),W
	BTRSS	STATUS,2
	MGOTO	_00168_DS_
	MOVIA	0xdc
	SUBAR	_mKeyUpCont,W
_00168_DS_:
	BTRSS	STATUS,0
	MGOTO	_00133_DS_
	.line	422, "components\touch_key\touch_key.c"; 	mRefValue = cap_value;
	BANKSEL	r0x1008
	MOVR	r0x1008,W
	BANKSEL	_mRefValue
	MOVAR	_mRefValue
	BANKSEL	r0x1007
	MOVR	r0x1007,W
	BANKSEL	_mRefValue
	MOVAR	(_mRefValue + 1)
	.line	423, "components\touch_key\touch_key.c"; 	mKeyUpCont = 0;
	BANKSEL	_mKeyUpCont
	CLRR	_mKeyUpCont
	CLRR	(_mKeyUpCont + 1)
_00133_DS_:
	.line	431, "components\touch_key\touch_key.c"; 	}
	RETURN	
; exit point of _TouchKey_Scan

;***
;  pBlock Stats: dbName = C
;***
;has an exit
;functions called:
;   _CapSS_Init
;   _CapSS_GetValue
;   _CapSS_Init
;   _CapSS_GetValue
;2 compiler assigned registers:
;   r0x100D
;   STK00
;; Starting pCode block
.segment "code"; module=touch_key, function=_TouchKey_Init
	.debuginfo subprogram _TouchKey_Init
;local variable name mapping:
	.debuginfo variable _reset_ref=r0x100D,enc=unsigned
_TouchKey_Init:
; 2 exit points
	.line	97, "components\touch_key\touch_key.c"; 	void TouchKey_Init(bool reset_ref)
	BANKSEL	r0x100D
	MOVAR	r0x100D
	.line	106, "components\touch_key\touch_key.c"; 	_TouchKey_CapSSInit();
	MCALL	_CapSS_Init
	.line	109, "components\touch_key\touch_key.c"; 	if (reset_ref)
	BANKSEL	r0x100D
	MOVR	r0x100D,W
	BTRSC	STATUS,2
	MGOTO	_00106_DS_
	.line	138, "components\touch_key\touch_key.c"; 	mRefValue = _TouchKey_CapSSGetValue(0);
	MCALL	_CapSS_GetValue
	BANKSEL	_mRefValue
	MOVAR	(_mRefValue + 1)
	MOVR	STK00,W
	MOVAR	_mRefValue
_00106_DS_:
	.line	141, "components\touch_key\touch_key.c"; 	TouchKey_mKeyStatus = false;
	BANKSEL	_TouchKey_mKeyStatus
	CLRR	_TouchKey_mKeyStatus
	.line	207, "components\touch_key\touch_key.c"; 	}
	RETURN	
; exit point of _TouchKey_Init


;	code size estimation:
;	  137+   46 =   183 instructions (  458 byte)

	end
